import { createApp } from "vue";
import "./style.css";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import router from "./router";
import App from "./App.vue";
import "./assets/less/index.less";
import store from "./store/index.js";
import "./api/mock.js";
import api from "./api/api";
import bcrypt from "bcryptjs";
import md5 from "js-md5";
import zhCn from "element-plus/es/locale/lang/zh-cn";

//图标
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import "./assets/iconfont/iconfont.js";
// 在 src/main.js 内引入注册脚本
import "virtual:svg-icons-register";
// 全局注册组件 src/main.js
import svgIcon from "./components/svgIcon/index.vue";

const app = createApp(App);
// elementplus图标配置
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.component("svg-icon", svgIcon);
// ep组件转换成中文
app.use(ElementPlus, {
  locale: zhCn,
});

// 页面刷新时，先于router前添加好动态路由
store.commit("addMenu", router);
app.use(router).use(store);
// 将请求api绑定到全局属性上
app.config.globalProperties.$api = api;
// bcrypt加密
app.config.globalProperties.$bcrypt = bcrypt;
// md5加密
app.config.globalProperties.$md5 = md5;
// app.use(VueNativeSock);
app.mount("#app");

//用于登录失败后跳转路由，request.js
export { app, router };
